#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

void error(char *msg)
{
	fprintf(stderr,"%s: %s\n", msg, strerror(errno));
	exit(1);
}

int main()
{
	int pipe_fd[2];
	char buf_r[80];
	int byten;
	pid_t pid;

	if(pipe(pipe_fd) < 0){
		error("pipe create error");
	}else{
		printf("pipe create seccess \n");
	}

	switch (fork()){
	case -1:
		error("fork error");
		break;
	case 0:
		close(pipe_fd[0]);
		if(write(pipe_fd[1], "hello", 6) != -1){
			printf("child send hello\n");
		}
		close(pipe_fd[1]);
		break;
	default:
		close(pipe_fd[1]);
		printf("hello world\n");
		if((byten=read(pipe_fd[0], buf_r, 80))>0){
			printf("%d bytes read from the pipe is %s\n",
				byten, buf_r);
		}
		close(pipe_fd[0]);
		break;
	}
	return 0;
}
